<template>
  <div>
    <p>
      <button @click="add()" class="btn btn-white btn-default btn-round">
        <i class="ace-icon fa fa-edit blue"></i>
        新增
      </button>
      &nbsp;
      <button @click="list()" class="btn btn-white btn-default btn-round">
        <i class="ace-icon fa fa-refresh "></i>
        刷新
      </button>
    </p>

    <table id="simple-table" class="table  table-bordered table-hover">
      <thead>
      <tr>
        <th class="center">
          <label class="pos-rel">
            <input type="checkbox" class="ace"/>
            <span class="lbl"></span>
          </label>
        </th>
                    <th>  id</th>
          <th>  标题</th>
          <th>  课程</th>
          <th>  大章</th>
          <th>  视频</th>
          <th>  时长</th>
          <th>  收费</th>
          <th>  顺序</th>
          <th>  创建时间</th>
          <th>  修改时间</th>
          <th>  vod</th>
        <th>操作</th>
      </tr>
      </thead>

      <tbody>
      <tr v-for="section in sections">
        <td class="center">
          <label class="pos-rel">
            <input type="checkbox" class="ace"/>
            <span class="lbl"></span>
          </label>
        </td>
              <td>
                  {{section.id}}
              </td>
              <td>
                  {{section.title}}
              </td>
              <td>
                  {{section.courseId}}
              </td>
              <td>
                  {{section.chapterId}}
              </td>
              <td>
                  {{section.video}}
              </td>
              <td>
                  {{section.time}}
              </td>
              <td>
                  {{section.charge}}
              </td>
              <td>
                  {{section.sort}}
              </td>
              <td>
                  {{section.createdAt}}
              </td>
              <td>
                  {{section.updatedAt}}
              </td>
              <td>
                  {{section.vod}}
              </td>

        <td>
          <div class="hidden-sm hidden-xs btn-group">
            <button class="btn btn-xs btn-success">
              <i class="ace-icon fa fa-check bigger-120"></i>
            </button>

            <button @click="edit(section)" class="btn btn-xs btn-info">
              <i class="ace-icon fa fa-pencil bigger-120"></i>
            </button>

            <button @click="del(section.id)" class="btn btn-xs btn-danger">
              <i class="ace-icon fa fa-trash-o bigger-120"></i>
            </button>

            <button class="btn btn-xs btn-warning">
              <i class="ace-icon fa fa-flag bigger-120"></i>
            </button>
          </div>

          <div class="hidden-md hidden-lg">
            <div class="inline pos-rel">
              <button class="btn btn-minier btn-primary dropdown-toggle" data-toggle="dropdown" data-position="auto">
                <i class="ace-icon fa fa-cog icon-only bigger-110"></i>
              </button>

              <ul
                class="dropdown-menu dropdown-only-icon dropdown-yellow dropdown-menu-right dropdown-caret dropdown-close">
                <li>
                  <a href="#" class="tooltip-info" data-rel="tooltip" title="View">
					<span class="blue">
						<i class="ace-icon fa fa-search-plus bigger-120"></i>
					</span>
                  </a>
                </li>

                <li>
                  <a href="#" class="tooltip-success" data-rel="tooltip" title="Edit">
					<span class="green">
						<i class="ace-icon fa fa-pencil-square-o bigger-120"></i>
					</span>
                  </a>
                </li>

                <li>
                  <a href="#" class="tooltip-error" data-rel="tooltip" title="Delete">
					<span class="red">
						<i class="ace-icon fa fa-trash-o bigger-120"></i>
					</span>
                  </a>
                </li>
              </ul>
            </div>
          </div>
        </td>
      </tr>
      </tbody>
    </table>
    <pagination ref="pagination" v-bind:list="list"></pagination>

    <div id="form-modal" class="modal fade" tabindex="-1" role="dialog">
      <div class="modal-dialog" role="document">
        <div class="modal-content">
          <div class="modal-header">
            <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
              aria-hidden="true">&times;</span></button>
            <h4 class="modal-title">表单</h4>
          </div>
          <div class="modal-body">
            <form class="form-horizontal">


                        <div class="form-group">
                            <label class="col-sm-2 control-label">id</label>
                            <div class="col-sm-10">
                                <input type="text" v-model="section.id" class="form-control" placeholder="id">
                            </div>
                        </div>



                        <div class="form-group">
                            <label class="col-sm-2 control-label">标题</label>
                            <div class="col-sm-10">
                                <input type="text" v-model="section.title" class="form-control" placeholder="标题">
                            </div>
                        </div>



                        <div class="form-group">
                            <label class="col-sm-2 control-label">课程</label>
                            <div class="col-sm-10">
                                <input type="text" v-model="section.courseId" class="form-control" placeholder="课程">
                            </div>
                        </div>



                        <div class="form-group">
                            <label class="col-sm-2 control-label">大章</label>
                            <div class="col-sm-10">
                                <input type="text" v-model="section.chapterId" class="form-control" placeholder="大章">
                            </div>
                        </div>



                        <div class="form-group">
                            <label class="col-sm-2 control-label">视频</label>
                            <div class="col-sm-10">
                                <input type="text" v-model="section.video" class="form-control" placeholder="视频">
                            </div>
                        </div>



                        <div class="form-group">
                            <label class="col-sm-2 control-label">时长</label>
                            <div class="col-sm-10">
                                <input type="text" v-model="section.time" class="form-control" placeholder="时长">
                            </div>
                        </div>



                        <div class="form-group">
                            <label class="col-sm-2 control-label">收费</label>
                            <div class="col-sm-10">
                                <input type="text" v-model="section.charge" class="form-control" placeholder="收费">
                            </div>
                        </div>



                        <div class="form-group">
                            <label class="col-sm-2 control-label">顺序</label>
                            <div class="col-sm-10">
                                <input type="text" v-model="section.sort" class="form-control" placeholder="顺序">
                            </div>
                        </div>



                        <div class="form-group">
                            <label class="col-sm-2 control-label">创建时间</label>
                            <div class="col-sm-10">
                                <input type="text" v-model="section.createdAt" class="form-control" placeholder="创建时间">
                            </div>
                        </div>



                        <div class="form-group">
                            <label class="col-sm-2 control-label">修改时间</label>
                            <div class="col-sm-10">
                                <input type="text" v-model="section.updatedAt" class="form-control" placeholder="修改时间">
                            </div>
                        </div>



                        <div class="form-group">
                            <label class="col-sm-2 control-label">vod</label>
                            <div class="col-sm-10">
                                <input type="text" v-model="section.vod" class="form-control" placeholder="vod">
                            </div>
                        </div>

            </form>
          </div>

          <div class="modal-footer">
            <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
            <button type="button" @click="save()" class="btn btn-primary">保存</button>
          </div>
        </div><!-- /.modal-content -->
      </div><!-- /.modal-dialog -->
    </div><!-- /.modal -->
  </div><!-- /.span -->

</template>

<script>
    import Pagination from "../../components/pagination";

    export default {
        components: {Pagination},
        name: "section",

        data: function () {
            return {
            section:
            {
            }
        ,
            sections: [],
        }
        },
        mounted: function () {
            //    this.$parent.activeSidebar("business-section-sidebar");
            let _this = this;
            _this.$refs.pagination.size = 5;
            _this.list(1);
        },
        methods: {
            list(page) {
                Loading.show();
                let _this = this;
                _this.$ajax.post(process.env.VUE_APP_SERVER + "/business/admin/section/list", {
                    page: page,
                    size: _this.$refs.pagination.size,
                }).then((response) => {
                    //     console.log("集合为", response.data);
                    let req = response.data;
                    Loading.hide();
                    _this.sections = req.content.list;
                    _this.$refs.pagination.render(page, req.content.total);

                })
            },
            save() {
                let _this = this;
              // 保存校验
              if (1 != 1
                      || !Validator.require(_this.section.title, "标题")
                      || !Validator.length(_this.section.title, "标题", 1, 50)
                      || !Validator.length(_this.section.video, "视频", 1, 200)
              ) {
                return;
              }

              //校验
                //       if(!Validator.require(_this.section.name,"名称")
                //          ||! Validator.require(_this.section.courseId,"课程ID")
                //           ||! Validator.length(_this.section.courseId,"课程ID",1,8)
                //      ){
                //         return;
                //     }
                _this.$ajax.post(process.env.VUE_APP_SERVER + "/business/admin/section/save", this.section).then((response) => {
                    //  console.log("保存", response.data);
                    let req = response.data;
                    if (req.success) {

                        $("#form-modal").modal("hide");
                        _this.list(1);
                        Toast.success("保存成功");
                    } else {
                        Toast.warning(req.message);
                    }

                })
            },

            del(id) {
                let _this = this;
                Confirm.show("删除小节后不可以恢复", function () {

                    _this.$ajax.delete(process.env.VUE_APP_SERVER + "/business/admin/section/del/" + id).then((response) => {
                        //   console.log("删除", response.data);
                        let req = response.data;
                        if (req.success) {
                            _this.list(1);
                            Toast.success("删除成功");
                        }
                    })


                })
            },


            add() {
                let _this = this;
                _this.section = {};

                $("#form-modal").modal({backdrop: "static"});
                $("#form-modal").modal("show");
            },

            edit(section) {
                let _this = this;
                $("#form-modal").modal({backdrop: "static"});
                $("#form-modal").modal("show");
                _this.section = $.extend({}, section);
            }

        }
    }
</script>

<style scoped>

</style>